Page({
  data: {
    categories: [
      { id: 1, name: '推荐' },
      { id: 2, name: '家电' },
      { id: 3, name: '手机' },
      { id: 4, name: '平板' },
      { id: 5, name: '配件' },
      { id: 6, name: '电脑' },
      { id: 7, name: '智能穿戴' },
      { id: 8, name: '其他' }
    ],
    activeCategoryId: 1,
    banners: [
      { id: 1, img: '/assets/shop_images/banner1.jpg' }
    ],
    goodsList: []
  },
  onLoad() {
    this.loadGoods(this.data.activeCategoryId);
  },
  onCategoryTap(e) {
    const id = e.currentTarget.dataset.id;
    this.setData({ activeCategoryId: id });
    this.loadGoods(id);
  },
  loadGoods(categoryId) {
    let goods = [];
    switch (Number(categoryId)) {
      case 2: // 家电
        goods = [
          { id: 101, name: '空调遥控器', img: '/assets/shop_images/air_remote.png', price: 35 },
          { id: 102, name: '洗衣机进水管', img: '/assets/shop_images/water_pipe.png', price: 18 },
          { id: 103, name: '电视挂架', img: '/assets/shop_images/tv_mount.png', price: 45 }
        ]; break;
      case 3: // 手机
        goods = [
          { id: 201, name: '手机电池', img: '/assets/shop_images/phone_battery.png', price: 99 },
          { id: 202, name: '手机屏幕', img: '/assets/shop_images/phone_screen.png', price: 299 },
          { id: 203, name: '充电器', img: '/assets/shop_images/charger.png', price: 39 }
        ]; break;
      case 4: // 平板
        goods = [
          { id: 301, name: '平板保护壳', img: '/assets/shop_images/pad_case.png', price: 59 },
          { id: 302, name: '平板屏幕', img: '/assets/shop_images/pad_screen.png', price: 199 },
          { id: 303, name: '数据线', img: '/assets/shop_images/data_cable.png', price: 19 }
        ]; break;
      case 5: // 配件
        goods = [
          { id: 401, name: '耳机', img: '/assets/shop_images/earphone.png', price: 69 },
          { id: 402, name: '充电宝', img: '/assets/shop_images/power_bank.png', price: 89 },
          { id: 403, name: '数据线', img: '/assets/shop_images/data_cable.png', price: 19 }
        ]; break;
      case 6: // 电脑
        goods = [
          { id: 501, name: '鼠标', img: '/assets/shop_images/mouse.png', price: 49 },
          { id: 502, name: '键盘', img: '/assets/shop_images/keyboard.png', price: 79 },
          { id: 503, name: '内存条', img: '/assets/shop_images/ram.png', price: 199 }
        ]; break;
      case 7: // 智能穿戴
        goods = [
          { id: 601, name: '手环表带', img: '/assets/shop_images/band_strap.png', price: 29 },
          { id: 602, name: '充电底座', img: '/assets/shop_images/charging_dock.png', price: 39 }
        ]; break;
      case 8: // 其他
        goods = [
          { id: 701, name: '万能遥控', img: '/assets/shop_images/universal_remote.png', price: 59 },
          { id: 702, name: '清洁套装', img: '/assets/shop_images/clean_kit.png', price: 25 }
        ]; break;
      default: // 推荐
        goods = [
          { id: 101, name: '空调遥控器', img: '/assets/shop_images/air_remote.png', price: 35 },
          { id: 201, name: '手机电池', img: '/assets/shop_images/phone_battery.png', price: 99 },
          { id: 401, name: '耳机', img: '/assets/shop_images/earphone.png', price: 69 }
        ];
    }
    this.setData({ goodsList: goods });
  },
  onSelectProduct(e) {
    const product = e.currentTarget.dataset.product;
    wx.setStorageSync('selectedProduct', product.name);
    wx.showToast({ title: '已选择', icon: 'success' });
  }
}); 